<!--
* @description 选择合同列表
!-->

<!-- 单页面需要多个上传组件 -->
<template>
  <div>
    <el-dialog
      title="选择提单号（直接点击单条记录）"
      :before-close="tableSelect"
      :visible.sync="dialogFormVisible"
      width='70%'
    >
      <div>
        <div class="flex-row rightSearchBlock-search" style="padding: 0">
          <div class="search-item flex-row flex-alignCenter">
            <div style="margin-right: 10px; white-space: nowrap">合同号</div>
               <el-select
              clearable
              size="small"
              filterable
              v-model="searchList.contractCode"
              @change="getData()"
              placeholder=""
            >
              <el-option
                v-for="item in $store.state.contractAllList"
                :key="item.id"
                :label="item.contractCode"
                :value="item.contractCode"
              >
              </el-option>
            </el-select>
          </div>
          <div class="search-item flex-row flex-alignCenter">
            <div style="margin-right: 10px; white-space: nowrap">船名</div>
            <el-select
              clearable
              size="small"
              filterable
              v-model="searchList.shipName"
              @change="getData()"
              placeholder=""
            >
              <el-option
                v-for="item in $store.state.typeAllList['船名']"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              >
              </el-option>
            </el-select>
          </div>
        </div>
        <!-- 表格 -->
        <div style="margin-top: 10px">
          <el-table
            :data="tableData.records"
            style="width: 100%"
            highlight-current-row
            @current-change="tableSelect"
          >
            <el-table-column
              prop="code"
              label="编号"
               :width="flexColumnWidth('code',tableData.records)"
            ></el-table-column>
            <el-table-column
              prop="contractCode"
              label="合同号"
              :width="flexColumnWidth('contractCode',tableData.records)"
              
            ></el-table-column>
            <el-table-column
              prop="invoiceCode"
              label="发票号"
              :width="flexColumnWidth('invoiceCode',tableData.records)"
            ></el-table-column>
            <el-table-column
              prop="shipName"
              label="船名"
             :width="flexColumnWidth('shipName',tableData.records)"
            ></el-table-column>
            <el-table-column
              prop="ladingBillCode"
              label="提单号"
              :width="flexColumnWidth('ladingBillCode',tableData.records)"
            ></el-table-column>
            <el-table-column
              prop="tradeType"
              label="贸易方式"
              
            ></el-table-column>
            <el-table-column
              prop="shipmentType"
              label="装运方式"
              
            ></el-table-column>
            <el-table-column
              prop="originalCountry	"
              label="起运国"
              
            ></el-table-column>
            <el-table-column
              prop="loadingPort"
              label="装货港"
              :width="flexColumnWidth('loadingPort',tableData.records)"
            ></el-table-column>
            <el-table-column
              prop="deliveryPort"
              label="到货港"
             :width="flexColumnWidth('deliveryPort',tableData.records)"
              
            ></el-table-column>
            <el-table-column
              prop="priceClause"
              label="价格条款"
              width="120"
              
            ></el-table-column>
            <el-table-column
              prop="currency"
              label="币种"
              width="120"
              
            ></el-table-column>
            <el-table-column
              prop="amount"
              label="金额"
                                          :width="flexColumnWidth('amount',tableData.records)"

            ></el-table-column>

            <el-table-column prop="volume" label="体积" :width="flexColumnWidth('volume',tableData.records)">
              <template slot-scope="scope">
                <div>
                  {{ scope.row.volume }}{{ scope.row.volumeUnit }}
                </div></template
              ></el-table-column
            >
            <el-table-column prop="weight" label="重量" :width="flexColumnWidth('weight',tableData.records)">
              <template slot-scope="scope">
                <div>
                  {{ scope.row.weight }}{{ scope.row.weightUnit }}
                </div></template
              ></el-table-column
            >
          </el-table>
        </div>
        <!-- 分页 -->
        <div
          v-if="tableData.total"
          class="block"
          style="margin-top: 10px; text-align: right"
        >
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="searchList.pageNum"
            :page-size="searchList.pageSize"
            layout="sizes,total, prev, pager, next, jumper" :page-sizes="[7, 20, 30, 40]"
            :total="Number(tableData.total)"
          ></el-pagination>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="confirm_contract(contractDetail)"
          >确 定</el-button
        >
        <el-button @click="dialogFormVisible = false">取 消</el-button> -->
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "page",
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: "进口",
    },
  },
  data() {
    return {
      tableData: { records: [{}] },
      searchList: {
        pageNum: 1,
        pageSize: 7,
      },
    };
  },
  created() {
    this.getData();
  },
  methods: {
      //增加搜索条件
    addSearchCriteria(key, value) {
      this.searchList[key] = value;
      console.log(this.searchList)
    },
    tableSelect(val) {
      this.$emit("saveId", val);
    },
    //分页选择每页多少条
    handleSizeChange(val) {this.searchList.pageSize = val; this.getData();},
    //分页当前页
    handleCurrentChange(val) {
      this.searchList.pageNum = val;
      this.getData();
    },
    getData(pageNum) {
      this.searchList.type = this.type;
      this.$myApi.page_doc(this.searchList).then((res) => {
        if (res.code == 200) {
          this.tableData = res.data;
        }
      });
    },
  },
};
</script>
